package com.tgu.home_action.config;

import com.tgu.home_action.controller.filter.CORSInterceptor;
import com.tgu.home_action.controller.filter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private CORSInterceptor corsInterceptor;
    @Autowired
    private LoginInterceptor loginInterceptor;

    String[] loginPaths = new String[]{
            "/family/**",
            "/volunteer/**",
            "/admin/**",
            "/case/**",
            "/notice/**",
            "/face/**",
            "/mark/**",
            "/memo/**"
    };

    String[] unLoginPaths = new String[]{
            "/*/login",
            "/*/refresh",
            "/case/number",
            "/volunteer/number",
            "/volunteer/onlineNumber",
            "/notice",
            "/notice/banner",
            "/thirdParty/notFound",
            "/thirdParty/login",
            "/thirdParty/refresh",
            "/thirdParty/case/id"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(corsInterceptor).addPathPatterns("/**");
        registry.addInterceptor(loginInterceptor).addPathPatterns(loginPaths).excludePathPatterns(unLoginPaths);
    }


}
